package com.xy.generate.generator;

import cn.hutool.core.bean.BeanUtil;

import java.io.*;

public class JarGenerator {
    public static void doGenerate(String projectPath) throws IOException, InterruptedException {
        //maven打包命令
        String command = "mvn.cmd clean package -DskipTests=true";
        ProcessBuilder pb = new ProcessBuilder(command.split(" "));
        //命令在那个目录下执行
        pb.directory(new File(projectPath));
        Process start = pb.start();
        //读取命令的输出
        InputStream inputStream = start.getInputStream();
        //转换成bufferRead
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }
        //等到命令执行完成
        int exitCode = start.waitFor();
        System.out.println("命令执行结束: 结束码" + exitCode);
    }

    public static void main(String[] args) {
        try {
            doGenerate("D:\\JavaProject\\xy-generate\\xy-generate-marker\\generated\\acm-template-pro-generate");
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
